<template>

<div class="col-sm-6 col-sm-offset-3 ">
    <h2 class="text-center "> 为业务生成securiter key </h2>
    <form>
        <div class="form-group">
            <label>
                key
                <input id="key" v-model="key" class="form-control"> </input>
            </label>
        </div>

        <div class="form-group">
            <label>
               channel/topci
            <input id="channel" v-model="channel" class="form-control"> </input>
            </label>
        </div>

        <div class="container" >
            <label>
                enSub
                <input id="enSub" v-model="type.enSub" type="checkbox"> </input>
            </label>

            <br/>
    
            <label>
                    enPub
                <input id="enPub" v-model="type.enPub" type="checkbox"> </input>
            </label>

            <br/>
    
            <label>
                    enStore
                <input id="enStore" v-model="type.enStore"  type="checkbox"> </input>
            </label>
            <br/>
    
            <label>
                    enLoad
                <input id="enLoad" v-model="type.enLoad" type="checkbox"> </input>
            </label>
            <br/>
    
            <label>
                    enPresence
                <input id="enPresence" v-model="type.enPresence" type="checkbox"> </input>
            </label>
        </div>

        <div class="form-group ">
            <input type="submit" value="提交" @click.prevent.stop = "genKey" class="btn btn-lg"> </input>
        </div>

    </form>
</div>

</template>

<script>
export default { 
    name: 'genKey',
    data() { 
        return { 
            key: "",
            channel: "",
            type: {
                enSub: true,
                enPub: true,
                enStore: true,
                enLoad : true,
                enPresence: true
            }
        }
    },

    methods: {
        genKey() { 
            console.log( this.key, this.channel );
            var request = { 
                key: this.key,
                channel: this.channel,
                type:  (this.type.enSub ? "r": "") + 
                    ( this.type.enPub ? "w" : "") + 
                    ( this.type.enStore ? "s": "") +
                    ( this.type.enLoad ? "l": "") + 
                    ( this.type.enPresence ? "p": "")
            }
            console.log( "keygen request: ",  request )
            emitter = emitter.connect( { host: "localhost", port: 8000 } )
            emitter.on( "keygen", function( msg ) { 
                console.log( "keygen  : ",  msg )
            })
            emitter.keygen( request )
        },
    }
}

</script>

<style>
</style>
